<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of TimeInterval
 *
 * @author luisberrocal
 */
class TimeInterval {
   public $interval;
   public $nextDay;
   public function  __construct($interval, $nextDay = false) {
       $this->interval = $interval;
       $this->nextDay = $nextDay;
    }


   public function getDateTime(){
       return TimeInterval::convertToDateTime($this->interval, $this->nextDay);

   }
   public static function convertToDateTime($timeRange, $nextDay = false) {
        $basedate = "2010-01-01";
        if($nextDay){
            $basedate = "2010-01-02";
        }
        $times = explode("-", $timeRange);
        $start = new DateTime($basedate . " " . $times[0]);
        $end = new DateTime($basedate . " " . $times[1]);
        if ($end > $start) {
            return array("start" => $start, 'end' => $end);
        } else {
            $end->add(new DateInterval("P1D"));
            return array("start" => $start, 'end' => $end);
        }
    }
}


